home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld Secrets (4th Edition)
/
Mac Secrets CD 4th Ed.toast
/
Apple Advanced Technologies
/
Apple Speech Technologies 1.5
/
PlainTalk Developer Info
/
Speech Recognition Manager SDK
/
SR Sample Code
/
MakeStrLanguageModel
/
MakeStrLanguageModel.c
next >
Wrap
Text File
|
1996-02-22
|
3KB
|
111 lines
/************************************************************
Created: Wednesday, May 4, 1994 at 2:24:14 PM
MakeStrLanguageModel.c
An example function library which will build a
speech recognition language model from STR# resource(s).
Copyright Apple Computer, Inc. 1994
All rights reserved
************************************************************/
#include "MakeStrLanguageModel.h"
#include <TextUtils.h>
#include <Resources.h>
#include <Errors.h>
/*--------------------------------------------------------------------------------
* GetStrLMName
* reads the name of an 'STR#' resource for a language model
*/
static OSErr GetStrLMName (unsigned char *name, short stringListID)
{
Handle stringList;
short id; ResType type;
OSErr status = noErr;
/* don't cause resource to load for this function */
SetResLoad (false);
/* get a handle to the resource */
stringList = GetResource ('STR#', stringListID);
if (stringList) {
/* read its name for the language model */
GetResInfo (stringList, &id, &type, name);
/* if it isn't loaded, then release the handle */
if (*stringList == NULL)
ReleaseResource (stringList);
}
/* if the resource was NOT found, then read the error code */
else {
status = ResError ();
/* see IM vol 1 for this case - no 'STR#' resources
in any file of the current resource chain,... */
if (status == noErr)
status = resNotFound;
}
/* restore ResLoad */
SetResLoad (true);
return status;
}
/*--------------------------------------------------------------------------------
* MakeStrLanguageModel
* builds a simple language model from an 'STR#' resource.
*
* this function is trivially embellished to provide for more
* complicated language structures, such as embedded language
* models
*/
OSErr MakeStrLanguageModel (SRRecognitionSystem recSystem,
SRLanguageModel *languageModel, short stringListID)
{
Str255 text;
SRLanguageModel lm = 0;
/* get the top level name */
OSErr status = GetStrLMName (text, stringListID);
/* if we found the resource, we can proceed */
if (status == noErr) {
/* allocate a language model */
status = SRNewLanguageModel (recSystem, &lm, &text[1], text[0]);
if (status == noErr) {
/* loop counter for phrases */
short phraseIndex = 0;
do {
/* read the text of the phrase */
GetIndString (text, stringListID, ++phraseIndex);
if (text[0])
/* add in the phrase text */
status = SRAddText (lm, &text[1], text[0], phraseIndex);
} while (status == noErr && text[0]);
/* dispose of the SRLanguageModel if there was an error */
if (status != noErr) {
SRReleaseObject (lm);
lm = 0;
}
}
}
/* return what was allocated */
*languageModel = lm;
return status;
}